package _interview75;

import java.util.PriorityQueue;
import java.util.Queue;

/**
 * 2336. 无限集中的最小数字
 */
public class No2336 {
    private final Queue<Integer> DB;
    private int index;

    public No2336() {
        DB = new PriorityQueue<>();
        index = 1;
    }

    public int popSmallest() {
        if (DB.isEmpty()) return index++;
        else return DB.peek() < index ? DB.poll() : index++;
    }

    public void addBack(int num) {
        if (index > num && !DB.contains(num)) DB.offer(num);
    }
}
